
/* endnote7; calculating intra-class correlations */
ods output CovParms = covp; proc mixed data=consultations; class agency; model hhi =            ; random intercept /subject=agency;
data icc; set covp end=last; retain bvar; if subject~="" then bvar = estimate; if last then icc = bvar/(bvar+estimate);
proc print data = icc;

ods output CovParms = covp; proc mixed data=consultations; class agency; model p_nonregulated = ; random intercept /subject=agency;
data icc; set covp end=last; retain bvar; if subject~="" then bvar = estimate; if last then icc = bvar/(bvar+estimate);
proc print data = icc;

ods output CovParms = covp; proc mixed data=consultations; class agency; model p_otherbusine = ; random intercept /subject=agency;
data icc; set covp end=last; retain bvar; if subject~="" then bvar = estimate; if last then icc = bvar/(bvar+estimate);
proc print data = icc;

ods output CovParms = covp; proc mixed data=consultations; class agency; model p_nonbusiness = ; random intercept /subject=agency;
data icc; set covp end=last; retain bvar; if subject~="" then bvar = estimate; if last then icc = bvar/(bvar+estimate);
proc print data = icc;

ods output CovParms = covp; proc mixed data=consultations; class agency; model p_experts        = ; random intercept /subject=agency;
data icc; set covp end=last; retain bvar; if subject~="" then bvar = estimate; if last then icc = bvar/(bvar+estimate);
proc print data = icc;
run;

/* modelling only intercept */
proc glimmix data=consultations empirical; 
 class agency;
 model hhi=/cl dist=binomial link=logit solution chisq;
 random _residual_/subject=agency s type=vc residual;
 covtest/wald;
proc glimmix data=consultations empirical; 
 class agency;
 model p_nonregulated=/cl dist=binomial link=logit solution chisq;
 random _residual_/subject=agency s type=vc residual;
 covtest/wald;
run;

/* TABLE 5 PART I */
proc glimmix data=consultations empirical; 
 class agency consultationtype(ref='1') complexitytext(ref="1") format;
 model hhi=consultationtype complexitytext format legal hhic age duration l_mob_total
       /dist=binomial link=logit solution chisq oddsratio;
 random intercept/subject=agency type=vc;
 covtest/wald;
proc glimmix data=consultations empirical; 
 class agency consultationtype(ref='1') complexitytext(ref="1") format;
 model p_nonregulated=consultationtype complexitytext format legal hhic age duration l_mob_total
       /dist=binomial link=logit solution;
 random intercept/subject=agency type=vc;
 covtest/wald;
run;

/* TABLE 5 PART II */
proc glimmix data=consultations empirical; 
 class agency consultationtype(ref='1') complexitytext(ref="1") format;
 model hhi=consultationtype complexitytext format legal hhic age legal*hhic legal*age duration l_mob_total
       /dist=binomial link=logit solution chisq oddsratio;
 random intercept/subject=agency type=vc;
 output out=predp pred(ilink)=p stdi=se; 
 covtest/wald;
proc means data=predp mean std maxdec=2; var p; class legal agency; run;

proc glimmix data=consultations empirical; 
 class agency consultationtype(ref='1') complexitytext(ref="1") format;
 model p_nonregulated=consultationtype complexitytext format legal hhic age legal*hhic legal*age duration l_mob_total
       /dist=binomial link=logit solution;
 random intercept/subject=agency type=vc;
 output out=predp pred(ilink)=p stdi=se; 
 covtest/wald;
proc means data=predp mean std maxdec=2; var p; class legal agency; run;

/* TABLE 5 PART III */
proc glimmix data=consultations empirical; 
 class agency consultationtype(ref='1') complexitytext(ref="1") format;
 model p_otherbusine=consultationtype complexitytext format legal hhic age legal*hhic legal*age duration l_mob_total
       /dist=binomial link=logit solution chisq oddsratio;
 random intercept/subject=agency type=vc;
 covtest/wald;
 output out=predp pred(ilink)=p stdi=se; 
proc means data=predp mean std maxdec=2; var p; class legal agency; run;

proc glimmix data=consultations empirical; 
 class agency consultationtype(ref='1') complexitytext(ref="1") format;
 model p_nonbusiness=consultationtype complexitytext format legal hhic age legal*hhic legal*age duration l_mob_total
       /dist=binomial link=logit solution chisq oddsratio;
 random intercept/subject=agency type=vc;
 covtest/wald;
 output out=predp pred(ilink)=p stdi=se; 
proc means data=predp mean std maxdec=2; var p; class legal agency;
proc means data=predp mean std maxdec=2; var p; class complexitytext;
proc means data=predp mean std maxdec=2; var p; class consultationtype; run;

proc glimmix data=consultations empirical; 
 class agency consultationtype(ref='1') complexitytext(ref="4") format;
 model p_experts=consultationtype complexitytext format legal hhic age legal*hhic legal*age duration l_mob_total
       /dist=binomial link=logit solution chisq oddsratio;
 random intercept/subject=agency type=vc;
 covtest/wald;
 output out=predp pred(ilink)=p stdi=se; 
proc means data=predp mean std maxdec=2; var p; class legal agency; 
proc means data=predp mean std maxdec=2; var p; class consultationtype; run;


